package chapterSystem.client.interfaceDrawing.activities;

import chapterSystem.client.ChapterSystemService;
import chapterSystem.client.callbacks.WriteSimpleEntityCallback;
import chapterSystem.client.model.entitiesInt.Brother;
import chapterSystem.client.model.entitiesInt.Report;
import chapterSystem.client.model.enums.ActivityType;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.StackLayoutPanel;
import com.google.gwt.user.client.ui.TextArea;

/**
 * User: Hasp
 * Date: 06.05.12
 * Time: 20:01
 */
public class EditReportActivity extends SubmitReportActivity {
    private final Report myReport;

    public EditReportActivity(final Brother brother, final ActivityType type, int eventId, Activity callback, Report myReport) {
        super(brother, type, eventId, callback);
        this.myReport = myReport;
        reportText.setText(myReport.getReport());
    }

    @Override
    protected ClickHandler createClickHandler(final TextArea reportText, final StackLayoutPanel workArea) {
        return new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                if (reportText.getText().trim().length() == 0) {
                    Window.alert("Write report!");
                } else {
                    ChapterSystemService.App.getInstance().editReport(myReport.setText(reportText.getText()),
                            new WriteSimpleEntityCallback(workArea, callback));
                }
            }
        };
    }
}
